$(function(){
    $("#addBtn").click(function(){
        var id = document.getElementById("buildId").value;
        window.location.href = window.ctx +"/room/add/" +id;
    });
    $("#clearBtn").click(function(){
        $("input[type = 'text']").val('');
        $("[name=isIn]").val('');
    });
    $("#delBtn").click(function(){
        $.ajax({
            url:window.ctx +"/rest/user/checkRole",
            dataType:"json",
            type:"post",
            success:function(data){
                if(data){
                    var checkedNum = $("input[name='subBox']:checked").length;
                    if (checkedNum == 0) {
                        art.dialog.tips("请至少选择一项!");
                        return false;
                    }
                    if (confirm("确定删除所选项目?")) {
                        var checkedList = new Array();
                        $("input[name='subBox']:checked").each(function () {
                            checkedList.push($(this).val());
                        });
                        $.ajax({
                            url:window.ctx +"/rest/room/checkRoomIsDel",
                            type:"post",
                            data: {"delitems": checkedList.toString()},
                            dataType:"json",
                            success: function (data) {
                                if (data){
                                    $.ajax({
                                        type: "post",
                                        url: window.ctx + "/rest/room/delByChecked",
                                        data: {"delitems": checkedList.toString()},
                                        datatype: "html",
                                        success: function (data) {
                                            $("[name='checkbox']:checkbox").attr("checked", false);
                                            art.dialog.tips('删除成功!');
                                            setTimeout("location.reload()", 1000);//页面刷新
                                        },
                                        error: function (data) {
                                            art.dialog.tips('删除失败!');
                                        }
                                    });
                                }else {
                                    art.dialog.tips('请勿选择不为空的房间!');
                                }

                            }
                        })
                    }
                }else {
                    art.dialog.tips('请勿选择不为空的房间!');
                }
            }
        })

    })
});
function selectAll(checkObj){
    if(checkObj.is(":checked")){
        $("input[type='checkbox']").prop("checked",true);
    }else{
        $("input[type='checkbox']").prop("checked",false);
    }
}